//初始化自定义菜单
// layui.use('jquery', function () {
//     var $ = layui.jquery;
//
//     // var script = document.createElement("script");
//     // script.type = "text/javascript";
//     // script.appendChild(document.createTextNode($("#aa").html()));
//     // document.body.appendChild(script);
//     // getPermission();
//
//
//     $.ajax({
//         type: "POST",
//         url: "/menu/getAll",
//         dataType: "json",
//         async:false,
//         contentType: "application/json",
//         success: function (data) {
//             var val ="";
//             for (var i = 0; i < data.length; i++) {
//                 for (var j = 0; j <data[i].length ; j++) {
//                     // if(i==0&j==0){
//                     //     //菜单默认展开
//                     //     //val='<li class="layui-nav-item layui-nav-itemed">';
//                     //     val+='<li class="layui-nav-item">';
//                     // }
//                     // if(i!=0&j==0){
//                     //     val+='<li class="layui-nav-item">';
//                     // }
//                     if(j==0){
//                         val+='<li class="layui-nav-item">';
//                         val+='<a href="javascript:;" url="'+data[i][j].url+'" title="'+data[i][j].title+'"><i class="'+data[i][j].icon+'"></i><cite class="menu">'+data[i][j].title+'</cite></a>';
//                         continue;
//                     }
//                     //如果只有2行
//                     if(j==1&&j==data[i].length-1){
//                         val+='<dl class="layui-nav-child">';
//                         val+='<dd><a style="padding-left: 45px;" href="javascript:;" url="'+data[i][j].url+'">'+data[i][j].title+'</a></dd></dl></li>';
//                         continue;
//                     }
//                     if(j==1&&j!=data[i].length-1){
//                         val+='<dl class="layui-nav-child">';
//                         val+='<dd><a style="padding-left: 45px;" href="javascript:;" url="'+data[i][j].url+'">'+data[i][j].title+'</a></dd>';
//                         continue;
//                     }
//                     if(j==data[i].length-1){
//                         val+='<dd><a style="padding-left: 45px;" href="javascript:;" url="'+data[i][j].url+'">'+data[i][j].title+'</a></dd></dl></li>';
//                     }else{
//                         val+='<dd><a style="padding-left: 45px;"href="javascript:;" url="'+data[i][j].url+'">'+data[i][j].title+'</a></dd>';
//                     }
//                 }
//             }
//
//             console.log(val);
//             $("#navtree").html(val);
//         },
//         error: function () {
//             console.log("菜单载入失败！");
//         }
//     });
// })

//初始化全局
layui.use(['table', 'form', 'jquery', 'element'], function () {
    var table = layui.table
        , form = layui.form
        , $ = layui.jquery
        , element = layui.element;

    //窗口宽度
    var windowWidth = $(window).width() ;

    //窗口宽度标准
    var windowWidthCriterion = 880;

    //窗口状态，缩小时为0，展开时为1
    var flexStatus;

    //菜单伸缩状态，隐藏状态0，显示图标状态60，展开状态200
    var menuStatus;

    //伸缩状态，true为伸缩动画完成，false为伸缩动画未完成
    var animateStatus = true;

    //伸缩速度
    var animateSpeed = 100;

    //载入时窗口宽度小于标准
    if(windowWidth<=windowWidthCriterion){
        flexStatus = 0;
        menuStatus = 0;
        $(".layui-body").css({"position":"relative","top":"0px"});
        $("#menu-button").find("i").attr("class", "layui-icon layui-icon-spread-left");
        $("#menu-button").attr("class", "showtab");

        $("#leftmenu").animate({left: $("#leftmenu").position().left - 200 + "px"},animateSpeed);
        //$(".layui-logo").animate({width: $(".layui-logo").width() - 200 + "px"},animateSpeed);
        $(".layui-side-menu").animate({width: $(".layui-side-menu").width() - 200 + "px"},animateSpeed);
        //正文伸缩
        $(".layui-body").animate({left: $(".layui-body").position().left - 200 + "px"},animateSpeed,null,function(){
            $("#logoStatus").val($("#logo").html());
            $("#logo").html("");
        });
    }
    if(windowWidth>windowWidthCriterion){
        flexStatus = 1;
        menuStatus = 200;
    }

    //控制菜单文本隐藏显示
    var menuTextChange = function(status){
        $(".layui-nav-tree").find("li").each(function (em, ind) {
            $(this).find("cite").css("display", status);
            $(this).find("dl").css("display", status);
        });
    }

    var menuButtonChange = function(status){
        if(status=="show"){
            $("#menu-button").attr("class", "showtab");
            $("#menu-button").find("i").attr("class", "layui-icon layui-icon-spread-left");
        }else if(status=="hide"){
            $("#menu-button").attr("class", "hidetab");
            $("#menu-button").find("i").attr("class", "layui-icon layui-icon-shrink-right");
        }

    }


    //当浏览器大小变化时
    $(window).resize(function () {
        windowWidth = $(window).width() ;
        //窗口宽度小于标准并且处于展开状态时
        if(windowWidth<=windowWidthCriterion&&flexStatus==1){
            //窗口伸缩状态为隐藏
            flexStatus = 0;

            if(menuStatus==60){//左侧菜单处于半收缩状态
                //logo恢复
                $("#logo").css("text-align","center");
                $("#companyName").css("display","none");
                $("#osName").css("display", "");
                //头部左侧图标
                $("#leftmenu").animate({left: $("#leftmenu").position().left - 60 + "px"},animateSpeed);
                //logo
                //$(".layui-logo").animate({width: $(".layui-logo").width() - 200 + "px"},animateSpeed);
                //左侧菜单
                $(".layui-side-menu").animate({width: $(".layui-side-menu").width() - 60 + "px"},animateSpeed);
                //正文伸缩
                $(".layui-body").animate({left: $(".layui-body").position().left - 60 + "px"},animateSpeed);
            }else{

                menuStatus = 0;
                //菜单收缩图标改变方向
                menuButtonChange("show");
                $("#leftmenu").animate({left: $("#leftmenu").position().left - 200 + "px"},animateSpeed);

                //$(".layui-logo").animate({width: $(".layui-logo").width() - 200 + "px"},animateSpeed);
                $(".layui-side-menu").animate({width: $(".layui-side-menu").width() - 200 + "px"},animateSpeed);
                //正文伸缩
                $(".layui-body").animate({left: $(".layui-body").position().left - 200 + "px"},animateSpeed);

            }

        }
        //窗口宽度大于标准并且处于缩小状态时
        if(windowWidth>windowWidthCriterion&&flexStatus==0){
            //窗口伸缩状态为展开
            flexStatus = 1;
            $(".layui-body").css({"position":"absolute","top":"60px"});
            if(menuStatus==60) {//左侧菜单处于图标状态
                console.log("小窗口处于图标状态");
                $("#logo").css("text-align","center");
                $("#companyName").css("display","none");
                $("#osName").css("display", "");
                $("#leftmenu").animate({left: $("#leftmenu").position().left + 200 + "px"},animateSpeed);
                //$(".layui-logo").animate({width: $(".layui-logo").width() + 200 + "px"},animateSpeed);
                $(".layui-side-menu").animate({width: $(".layui-side-menu").width() + 60 + "px"},animateSpeed);
                //正文伸缩
                $(".layui-body").animate({left: $(".layui-body").position().left + 60 + "px"},animateSpeed);
                //$("#logo").html($("#logoStatus").val());
            }
            else if(menuStatus==200){
                //$("#logo").html($("#logoStatus").val());
                $(".layui-header").animate( {left: $(".layui-header").position().left - 200+ "px"},animateSpeed);
                $("#leftmenu").animate({left: $("#leftmenu").position().left + 200 + "px"},animateSpeed);
                $(".layui-body").css({"position":"absolute","top":"60px"});
                //$(".layui-body").animate({left: $(".layui-body").position().left - 200 + "px"},animateSpeed);
                //$("#leftmenu").animate({left: $("#leftmenu").position().left + 200 + "px"},animateSpeed);
                //{left: $(".layui-header").position().left + 200+ "px"},animateSpeed);
                //$(".layui-logo").animate({width: $(".layui-logo").width() + 200 + "px"},animateSpeed);
            }
            else if(menuStatus==0){
                menuStatus = 200;
                //菜单收缩图标改变方向
                menuButtonChange("hide");
                $("#leftmenu").animate({left: $("#leftmenu").position().left + 200 + "px"},animateSpeed);
                //$(".layui-logo").animate({width: $(".layui-logo").width() + 200 + "px"},animateSpeed);
                $(".layui-side-menu").animate({width: $(".layui-side-menu").width() + 200 + "px"},animateSpeed);
                //正文伸缩
                $(".layui-body").animate({left: $(".layui-body").position().left + 200 + "px"},animateSpeed);
                // $("#logo").html($("#logoStatus").val());
            }
        }
    });


    //左侧垂直菜单监控
    element.on('nav(navtree)', function (elem) {
        //判断是否收缩状态
        if (menuStatus==60) {
            menuStatus=200;
            menuButtonChange("hide");
            menuTextChange("");
            $("#logo").css("text-align","center");
            $("#companyName").css("display","none");
            $("#osName").css("display", "");
            $(".layui-side-menu").animate({width: $(".layui-side-menu").width() + 140 + "px"},animateSpeed);
            $(".layui-body").animate({left: $(".layui-body").position().left + 140 + "px"},animateSpeed);
            $(".layui-layout-left").animate( {left: $(".layui-layout-left").position().left + 140+ "px"},animateSpeed);
        } else {
            //展开状态点击操作
            var url = $(this).attr("url");
                    if(url!="main"){
                        load($(this).attr("url"));
                        if(flexStatus==0){
                    menuButtonChange("show");
                    menuStatus=0;
                    $(".layui-body").css({"position":"absolute","top":"60px"});
                    $(".layui-side-menu").animate({width: $(".layui-side-menu").width() -200 + "px"},animateSpeed);
                    $(".layui-body").animate({left: $(".layui-body").position().left - 200 + "px"},animateSpeed);
                    $(".layui-header").animate({left: $(".layui-header").position().left - 200 + "px"},animateSpeed);
                }
            }


        }
    })

    //顶部左侧菜单监控
    element.on('nav(leftmenu)', function (elem) {
        while (!animateStatus)
        {

        }
        //隐藏显示侧边菜单
        if (elem[0].className == "hidetab") {//隐藏
            animateStatus = false;
            menuButtonChange("show");

            if(windowWidth<=windowWidthCriterion){
                $(".layui-body").css({"position":"absolute","top":"60px"});
                menuStatus = 0;
                $(".layui-side-menu").animate({width: $(".layui-side-menu").width() - 200 + "px"},animateSpeed);
                $(".layui-header").animate( {left: $(".layui-header").position().left - 200+ "px"},animateSpeed);
                $(".layui-body").animate({left: $(".layui-body").position().left - 200+ "px"},animateSpeed,null,function(){
                    animateStatus = true;
                });
            }else{
                $("#logo").css("text-align","left");
                $("#companyName").css("display","");
                $("#osName").css("display", "none");
                menuStatus = 60;
                //侧边菜单只显示图标
                menuTextChange("none");
                //侧边菜单伸缩
                $(".layui-side-menu").animate({width: $(".layui-side-menu").width() - 140 + "px"},animateSpeed);
                $(".layui-layout-left").animate( {left: $(".layui-layout-left").position().left - 140+ "px"},animateSpeed);
                //正文伸缩
                $(".layui-body").animate({left: $(".layui-body").position().left - 140 + "px"},animateSpeed,null,function(){
                    animateStatus = true;
                });
            }
        } else if (elem[0].className == "showtab") {//显示
            animateStatus = false;
            menuStatus = 200;
            menuButtonChange("hide");
            menuTextChange("");
            $("#logo").css("text-align","center");
            $("#companyName").css("display","none");
            $("#osName").css("display", "");
            if(windowWidth>windowWidthCriterion){
                console.log("大窗口显示菜单");
                $(".layui-side-menu").animate({width: $(".layui-side-menu").width() + 140 + "px"},animateSpeed);
                $(".layui-layout-left").animate( {left: $(".layui-layout-left").position().left + 140+ "px"},animateSpeed);
                $(".layui-body").animate({left: $(".layui-body").position().left + 140+ "px"},animateSpeed,null,function(){
                    animateStatus = true;
                });
            }else{
                console.log("小窗口显示菜单");
                //$("#logo").html($("#logoStatus").val());
                $(".layui-body").css({"position":"relative","top":"0px"});
                $(".layui-side-menu").animate({width: $(".layui-side-menu").width() + 200 + "px"},animateSpeed);
                $(".layui-header").animate( {left: $(".layui-header").position().left + 200+ "px"},animateSpeed);
                $(".layui-body").animate( {left: $(".layui-body").position().left + 200+ "px"},animateSpeed,null,function(){
                    animateStatus = true;
                });
            }
        }
    });


    var load = function(url) {
            switch (url) {
                case "table":
                    loadtable();
                    // userSearch();
                    form.render();
                    break;
                case "addMenu":
                    addMenu();
                    break;

                case "stock":
                    stock();
                    break;
                case "role":
                    role();
                    break;
                case "product":
                    product();
                    break;
                case "permission":
                    permission();
                    break;
                case "specificationDetail":
                    specificationDetail();
                    break;
                case "reimburse":
                    reimburse();
                    break;
                case "reimburseAudit":
                    reimburseAudit();
                    break;
                case "stockIn":
                    stockIn();
                    break;
                case "stockOut":
                    stockOut();
                    break;
                case "addStockOut":
                    addStockOut();
                    break;
                case "addStockIn":
                    addStockIn();
                    break;
                case "productStock":
                    productStock();
                    break;
                default:
                    layer.msg('还没添加内容，敬请期待！',
                        {icon: 2, time: 1000}
                    );
            }
    }


    var loadtable = function(){
        var html = '<div style="margin-top: 10px;margin-right: 20px">\n' +
            '    <form class="layui-form" action="javascript:;" id="selectStockForm">\n' +
            '        <div class="layui-form-item">\n' +
            '            <div class="layui-inline">\n' +
            '                <label class="layui-form-label">姓名</label>\n' +
            '                <div class="layui-input-inline">\n' +
            '                    <input type="text" name="userName" id="userName" autocomplete="off" placeholder="请输入姓名"\n' +
            '                           class="layui-input">\n' +
            '                </div>\n' +
            '            </div>\n' +
            '            <div class="layui-inline">\n' +
            '                <label class="layui-form-label">状态</label>\n' +
            '                <div class="layui-input-inline">\n' +
            '                    <select name="userStatus" lay-search="">\n' +
            '                        <option value=""></option>\n' +
            '                        <option value="0">启用</option>\n' +
            '                        <option value="1">禁用</option>\n' +
            '                    </select>\n' +
            '                </div>\n' +
            '            </div>\n' +
            '        </div>\n' +
            '            <div class="layui-form-item">\n' +
            '                <div class="layui-inline">\n' +
            '                    <label class="layui-form-label">手机</label>\n' +
            '                    <div class="layui-input-inline">\n' +
            '                        <input type="text" name="userMobilePhone" id="phone" lay-verify="datetime" placeholder="请输入手机"\n' +
            '                               autocomplete="off" class="layui-input">\n' +
            '                    </div>\n' +
            '                </div>\n' +
            '                <div class="layui-inline">\n' +
            '                    <label class="layui-form-label">部门</label>\n' +
            '                    <div class="layui-input-inline">\n' +
            '                        <input type="text" name="userApartment" id="apart" lay-verify="datetime" placeholder="请输入部门"\n' +
            '                               autocomplete="off" class="layui-input">\n' +
            '                    </div>\n' +
            '                </div>\n' +
            '                <div class="layui-inline">\n' +
            '                    <div class="layui-input-block">\n' +
            '                        <button class="layui-btn" lay-submit="" lay-filter="demo2" id="user-search">立即搜索</button>\n' +
            '                    </div>\n' +
            '                </div>\n' +
            '            </div>\n' +
            '\n' +
            '    </form>\n' +
            '</div>' +
            '<div style="margin-left: 10px;margin-right: 10px"><table class="layui-hide" id="test" lay-filter="test"></table></div>';
        $("#mainbody").html(html);
        //表格加载
        table.render({
            elem: '#test'
            , url: '/sys/user/list'
            , toolbar: 'default'
            , title: '用户数据表'
            , id: 'userTable' //用作主键 做刷新用
            , page: true
            , limit: 10//默认每页显示数量
            , limits: [10, 20, 30]//每页显示数量类型
            , cols: [[
                {type: 'checkbox'}
                , {type: 'numbers',title: '序号',width: 80}
                , {field: 'userAccount', title: '用户名', width: 120, align: 'center'}
                , {field: 'userRoleName', title: '角色', width: 120, align: 'center'}
                , {field: 'userName', title: '姓名', width: 120, align: 'center',sort: true}
                , {field: 'userSex', title: '性别', width: 80, align: 'center'}
                , {field: 'userMobilePhone', title: '手机', width: 150, align: 'center'}
                , {field: 'userApartment', title: '所属部门', align: 'center', width: 150}
                , {field: 'userCreateTime', title: '创建时间', align: 'center', width: 180,sort: true}
                , {field: 'userCreateUser', title: '创建人', align: 'center', width: 120}
                , {field: 'userUpdateTime', title: '更新时间', align: 'center', width: 180,sort: true}
                , {field: 'userUpdateUser', title: '更新人', align: 'center', width: 120}
                , {
                    field: 'userStatus', title: '启用/禁用', width: 100, align: 'center', templet: function (res) {
                        if (res.userStatus == 1) {
                            return '<input value="'+res.userId+'" hidden="hidden"><input type="checkbox"  lay-skin="switch" lay-filter=test1 lay-text="ON|OFF">';
                        } else {
                            return '<input value="'+res.userId+'" hidden="hidden"><input type="checkbox"  lay-skin="switch" lay-filter=test1 lay-text="ON|OFF" checked>';
                        }
                    }
                }
            ]]
        });

        //头工具栏事件
        table.on('toolbar(test)', function (obj) {
            var checkStatus = table.checkStatus(obj.config.id)
                , data = checkStatus.data; //获取选中的数据
            switch (obj.event) {
                case 'add':
                    layer.open({
                        title: ['添加用户', 'font-size:18px;']
                        , shade: 0.6 //遮罩透明度
                        , area: ['630px','500px']//宽度
                        , type: 2
                        , anim: 1 //0-6的动画形式，-1不开启
                        , content: "/sys/user/addButton"
                        , success: function (layero, index) {
                            //layer高度自适应
                            // layer.iframeAuto(index);
                            table.reload('userTable');
                        }

 /*                       , end: function () {
                            var handle_status = $("#handle_status").val();
                            console.log(handle_status);
                            if (handle_status == 1) {

                                $("#handle_status").val("");
                                layer.msg('同上', {
                                    icon: 1,
                                    time: 1000 //2秒关闭（如果不配置，默认是3秒）
                                }, function () {
                                });
                            } else if (handle_status == 2) {
                                layer.msg('添加失败',
                                    {icon: 2, time: 1000}
                                )
                            }
                        }*/

                    })
                    break;
                case 'update':
                    if (data.length === 0) {
                        layer.msg('请选择一行');
                    } else if (data.length > 1) {
                        layer.msg('只能同时编辑一个');
                    } else {
                        layer.open({
                            title: ['编辑用户', 'font-size:18px;']
                            , shade: 0.6 //遮罩透明度
                            , area: ['630px','500px']//宽度
                            , type: 2
                            , anim: 1 //0-6的动画形式，-1不开启
                            , content: "/sys/user/editButton/"+data[0].userId
                            , success: function (layero, index) {
                                //layer高度自适应
                                // layer.iframeAuto(index);
                                table.reload('userTable');
                            }
 /*                           , end: function () {
                                var handle_status = $("#handle_status").val();
                                console.log(handle_status);
                                if (handle_status == 1) {

                                    $("#handle_status").val("");
                                    layer.msg('同上', {
                                        icon: 1,
                                        time: 1000 //2秒关闭（如果不配置，默认是3秒）
                                    }, function () {
                                        table.reload('userTable');
                                    });
                                } else if (handle_status == 2) {
                                    layer.msg('编辑失败',
                                        {icon: 2, time: 1000}
                                    )
                                }
                            }*/

                        })
                        break;
                    }
                    break;
                case 'delete':
                    if (data.length === 0) {
                        layer.msg('请选择一行');
                    } else {
                        //页面删除效果
                        //$(".layui-form-checked").closest('tr[data-index]').remove();
                        var arr = new Array();
                        for (var i = 0; i < data.length; i++) {
                            arr.push(data[i].userId);
                        }
                        layer.confirm("确定删除吗?",{

                                btn: ['确定', '取消']
                               ,title:"提示"
                            }, function (index, layero) {
                                console.log(arr);
                                $.ajax({
                                    type: "POST",
                                    url: "/sys/user/delete",
                                    traditional: true,
                                    dataType: "json",
                                    contentType: "application/json",
                                    data: JSON.stringify(arr),
                                    success: function (data) {
                                        console.log(data);
                                        layer.msg("删除成功!",{ icon: 1, time: 1000 });
                                        table.reload('userTable');
                                    },
                                    error: function () {

                                        layer.msg(JSON.parse(data.responseText).message,{ icon: 1, time: 1000 });
                                    }
                                });
                            }
                        );
                        // $.ajax({
                        //     type: "POST",
                        //     url: "/sys/user/delete",
                        //     traditional: true,
                        //     data: JSON.stringify(arr),
                        //     dataType: "json",
                        //     contentType: "application/json",
                        //     success: function (data) {
                        //         console.log("调用删除方法成功！");
                        //     },
                        //     error: function () {
                        //
                        //         console.log("调用删除方法失败！");
                        //     }
                        // });
                    }
                    break;
            }
            ;
        });

        form.on('switch(test1)', function (data) {
            var x = data.elem.checked;
            if (x) {
                handleSwitch("确定启用吗？", data, x);
            } else {
                handleSwitch("确定禁用吗？", data, x);
            }


        });

        //监听搜索按钮
        form.on('submit(demo2)', function (data) {
            var status = data.field.userStatus;
            console.log(status);
            var userName = $("#userName").val();
            var phone = $("#phone").val();
            var apart = $("#apart").val();
            $.ajax({
                type: "GET",
                url: "/sys/user/list",
                traditional: true,
                // dataType: "json",
                contentType: "application/json",
                data: {
                    userName: userName,
                    userMobilePhone: phone,
                    userApartment: apart,
                    userStatus: status
                },
                success: function (data) {
                    table.reload('userTable', {
                        where: {"userName": userName, "userMobilePhone": phone, "userApartment": apart,"userStatus":status}
                    });
                },
                error: function (data) {

                    layer.msg(JSON.parse(data.responseText).message,{ icon: 1, time: 1000 });
                }
            });
            // table.reload('userTable', {
            //     where: {"userName": userName, "userMobilePhone": userMobilePhone, "userApartment": userApartment}
            // });
        });
        var handleSwitch = function (content, data, isChecked) {
            var tableDiv = $(data.othis);
            var tableId = tableDiv.parent().find("input").eq(0).val();
            var tableBut = tableDiv.find("em").html();
            var tableButId;
            if (tableBut=="ON"){
                tableButId = 0;
            }
            if (tableBut=="OFF") {
                tableButId = 1;
            }
            layer.open({
                content: content
                , btn: ['确定', '取消']
                , yes: function (index, layero) {
                    $.ajax({
                        url:'/sys/user/edit',
                        data:{
                            userId: tableId,
                            userStatus: tableButId
                        },
                        // dataType:'text',
                        type:'post',
                        success:function (data) {
                            console.log(data);
                            if (data == 'success'){
                                table.reload('userTable');
                            }else{
                                layer.msg('错误');
                            }
                        },
                        error: function (data) {

                            layer.msg(JSON.parse(data.responseText).message,{ icon: 1, time: 1000 });
                        }
                    });
                    data.elem.checked = isChecked;
                    form.render();
                    layer.close(layer.index);
                    //按钮【按钮一】的回调
                }
                , btn2: function (index, layero) {
                    //按钮【按钮二】的回调
                    data.elem.checked = !isChecked;
                    form.render();
                    layer.close(layer.index);
                    //return false 开启该代码可禁止点击该按钮关闭
                }
                , cancel: function () {
                    //右上角关闭回调
                    data.elem.checked = !isChecked;
                    form.render();
                    //return false 开启该代码可禁止点击该按钮关闭
                }
            });
            return false;
        }


    }

    var addMenu = function(){
        var html = '<div style="margin-top: 30px;margin-right: 20px" id="x">\n' +
            '<form class="layui-form" action="javascript:;" id="menuForm">\n' +
            '    <div class="layui-form-item" style="margin-bottom: 25px">\n' +
            '        <div class="layui-inline">\n' +
            '            <label class="layui-form-label"><h3>标题：</h3></label>\n' +
            '            <div class="layui-input-inline">\n' +
            '                <input type="text" name="title" lay-verify="required" autocomplete="off" class="layui-input">\n' +
            '            </div>\n' +
            '        </div>\n' +
            '        <div class="layui-inline" style="display: none">\n' +
            '            <label class="layui-form-label"><h3>URL：</h3></label>\n' +
            '            <div class="layui-input-inline">\n' +
            '                <input type="text" name="url"  autocomplete="off" class="layui-input">\n' +
            '            </div>\n' +
            '        </div>\n' +
            '    </div>\n' +
            '    <div class="layui-form-item" style="margin-bottom: 5px">\n' +
            '        <div class="layui-inline">\n' +
            '            <label class="layui-form-label"><h3>图标：</h3></label>\n' +
            '            <div class="layui-input-inline" style="width:75px;">\n' +
            '                <i class="layui-icon layui-icon-face-smile" style="font-size: 30px; color: #ff5722;" id="icon"></i>\n' +
            '            </div>\n' +
            '        </div>\n' +
            // '        <div class="layui-inline">\n' +
            // '            <button class="layui-btn layui-btn-radius layui-btn-warm layui-btn-sm" id="add">\n' +
            // '                <i class="layui-icon">&#xe608;</i> 选择图标\n' +
            // '            </button>\n' +
            // '        </div>\n' +
            '        <div class="layui-inline">\n' +
            '            <input type="text" style="display: none" class="layui-input" value="layui-icon layui-icon-face-smile" id="iconInput" name="icon">\n' +
            '        </div>\n' +
            '    </div>\n' +
            '    <div class="layui-form-item">\n' +
            '        <p style="color: #999;margin-left: 110px;margin-bottom: 30px">点击表情选择图标</p>\n' +
            '    </div>\n' +
            '    <div class="layui-form-item">\n' +
            '        <div class="layui-input-block">\n' +
            '            <button class="layui-btn" lay-submit="" lay-filter="demo1">立即提交</button>\n' +
            '            <button type="reset" class="layui-btn layui-btn-primary">重置</button>\n' +
            '        </div>\n' +
            '    </div>\n' +
            '</form>\n' +
            '</div>';
        $("#mainbody").html(html);
        layui.use(['layer', 'jquery','form'], function () {
            var layer = layui.layer
                , $ = layui.jquery
                ,form = layui.form;

            //监听提交
            form.on('submit(demo1)', function (data) {
                var str = JSON.stringify(data.field);
                $.ajax({
                    type: "POST",
                    url: "/addMenu",
                    data: str,
                    dataType: "json",
                    contentType:"application/json",
                    success: function(msg){
                        console.log("调用添加菜单方法成功！");
                        //$("#menuForm")[0].reset();
                        //form.render();
                        layer.msg('添加成功！', {
                            icon: 1,
                            time: 500 //如果不配置，默认是3秒
                        }, function () {
                            location.reload();
                        });
                    },
                    error:function (msg) {
                        console.log(str);
                        console.log("调用添加菜单方法失败！");
                        //清空表单
                        $("#menuForm")[0].reset();
                        form.render();
                    }
                });
            });


            $("#icon").click(function () {
                var index = parent.layer.getFrameIndex(window.name);
                if(flexStatus==0){
                    layer.open({
                        title: ['选择菜单图标', 'font-size:18px;']
                        , shade: 0.6 //遮罩透明度
                        , area: ['285px', '300px']//宽度
                        , shadeClose:true
                        , type: 2
                        , anim: 1 //0-6的动画形式，-1不开启
                        , content: "/table"
                    })
                }else{
                    layer.open({
                        title: ['选择菜单图标', 'font-size:18px;']
                        , shade: 0.6 //遮罩透明度
                        , area: ['630px', '500px']//宽度
                        , type: 2
                        , shadeClose:true
                        , anim: 1 //0-6的动画形式，-1不开启
                        , content: "/table"
                    })
                }

            });


        });
    }

    $(document).on('click', '#user-edit', function(data) {
        layer.open({
            title: ['修改资料', 'font-size:18px;']
            , shade: 0.6 //遮罩透明度
            , area: ['630px','500px']//宽度
            , type: 2
            , anim: 1 //0-6的动画形式，-1不开启
            , content: "/sys/user/userEdit"
            , success: function (layero, index) {
                //layer高度自适应
                // layer.iframeAuto(index);
                // table.reload('userTable');
            }
        })
    });

})










